/**
 * @author https://vue-admin-beautiful.com （不想保留author可删除）
 * @description router全局配置，如有必要可分文件抽离，其中asyncRoutes只有在intelligence模式下才会用到，vip文档中已提供路由的基础图标与小清新图标的配置方案，请仔细阅读
 */

import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layouts'
import EmptyLayout from '@/layouts/EmptyLayout'
import { publicPath, routerMode } from '@/config'
import PermissionType from '@/utils/PermissionType'

Vue.use(VueRouter)
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/401'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/weixin',
    component: () => import('@/views/weixin'),
    hidden: true
  },
  {
    path: '/wxcode',
    component: () => import('@/views/wxcode'),
    hidden: true
  },
  // {
  //   path: '/',
  //   name: 'index',
  //   component: () => import('@/views/index/index'),
  //   hidden: true,
  // },
]

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: 'index',
        name: 'Index',
        component: () => import('@/views/index/index'),
        meta: {
          title: '首页',
          icon: 'home',
          affix: true,
        },
      },
    ],
  },
  {
    path: '/sys',
    component: Layout,
    redirect: 'noRedirect',
    name: 'SysManagement',
    meta: { title: '系统管理', icon: 'tools', permissions: [PermissionType.sysAdmin] },
    children: [
      {
        path: 'org',
        name: 'sys_org_org',
        component: () => import('@/views/sys/org/org'),
        meta: { title: '组织架构', icon: 'cog' },
      },
      {
        path: 'orguser',
        name: 'sys_org_orguser',
        component: () => import('@/views/sys/org/orguser'),
        meta: { title: '用户管理', icon: 'cog' },
      },
      // {
      //   path: 'user',
      //   name: 'sys_user_user',
      //   component: () => import('@/views/sys/user/user'),
      //   meta: { title: '用户管理', icon: 'user' },
      // },
      {
        path: 'role',
        name: 'sys_role_role',
        component: () => import('@/views/sys/role/role'),
        meta: { title: '角色管理', icon: 'user-lock' },
      },
    ],
  },

  {
    path: '/gift',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Gift',
    meta: { title: '礼品信息', icon: 'database', permissions: [PermissionType.gift]   },
    children: [
      {
        path: 'type',
        name: 'Gift_Gift_type',
        component: () => import('@/views/gift/type/index'),
        meta: { title: '礼品分类', icon: 'cog', permissions: [PermissionType.gift_Type]  },
      },
      {
        path: 'giftadmin',
        name: 'Gift_Gift_Admin',
        component: () => import('@/views/gift/admin/index'),
        meta: { title: '礼品管理', icon: 'cog', permissions: [PermissionType.gift_Admin]  },
      },
    ],
  },

  {
    path: '/order',
    component: Layout,
    redirect: 'noRedirect',
    name: 'Order',
    meta: { title: '我的订单', icon: 'clipboard', permissions: [PermissionType.order]   },
    children: [
      {
        path: 'orderlist',
        name: 'Order_OrderList',
        component: () => import('@/views/order/orderList'),
        meta: { title: '礼品订单', icon: 'book', permissions: [PermissionType.order_admin]  },
      },
      {
        path: 'tsorderlist',
        name: 'Order_TSOrderList',
        component: () => import('@/views/order/tsorderList'),
        meta: { title: '特殊礼品订单', icon: 'book', permissions: [PermissionType.order_teshu]  },
      },
    ],
  },

  {
    path: '/shenhe',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ShenHe',
    meta: { title: '审核管理', icon: 'train', permissions: [PermissionType.shenHe]   },
    children: [
      {
        path: 'shenhelist',
        name: 'ShenHe_ShenHeList',
        component: () => import('@/views/shenhe/shenheList'),
        meta: { title: '订单审核', icon: 'file-alt', permissions: [PermissionType.order_shenHe]  },
      },
      {
        path: 'tsshenhelist',
        name: 'ShenHe_TSShenHeList',
        component: () => import('@/views/shenhe/tsshenheList'),
        meta: { title: '特殊订单审核', icon: 'file-alt', permissions: [PermissionType.order_shenHe2]  },
      },
      {
        path: 'shenhehistory',
        name: 'ShenHe_ShenHeHistory',
        component: () => import('@/views/shenhe/shenheHistory'),
        meta: { title: '审核历史', icon: 'mobile-alt', permissions: [PermissionType.order_shenHe_his]  },
      },
    ],
  },

  {
    path: '*',
    redirect: '/404',
    hidden: true,
  },
]

const router = new VueRouter({
  base: publicPath,
  mode: routerMode,
  scrollBehavior: () => ({
    y: 0,
  }),
  routes: constantRoutes,
})

export function resetRouter() {
  location.reload()
}

export default router
